package chen.jia.xin.finalproject.ReadContactors;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

import chen.jia.xin.finalproject.R;

public class AllContactorAdapter extends ArrayAdapter<EachContactor>{
    //listview子项布局XML文件
    private  int resouceID;
    public AllContactorAdapter(Context context, int resource, List<EachContactor> objects) {
        super(context, resource, objects);
        this.resouceID = resource;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //获取每一个子项
        EachContactor eachItem = getItem(position);
        View view;
        AllContactorAdapter.ViewHolder viewHolder;
        if(convertView == null){
            view = LayoutInflater.from(getContext()).inflate(resouceID,parent,false);
            viewHolder = new ViewHolder();
            viewHolder.user_name = view.findViewById(R.id.person_name);
            viewHolder.user_number = view.findViewById(R.id.person_number);
            view.setTag(viewHolder);
        }else {
            view = convertView;
            viewHolder = (AllContactorAdapter.ViewHolder) view.getTag();
        }
        viewHolder.user_name.setText(eachItem.getUser_name());
        viewHolder.user_number.setText(eachItem.getUser_number());
        return view;
    }
    class ViewHolder {
        TextView user_name;
        TextView user_number;
    }
}
